package com.hxm.webview.view;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.hxm.webview.R;
import com.hxm.webview.api.Api;
import com.hxm.webview.entity.WeChat;
import com.hxm.webview.http.HttpRequest;
import com.hxm.webview.http.listener.RequestListener;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
    private EditText editText;
    private Button button,btn_wechat;
    private String newsId;
    private TextView tv_wechat;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        editText= (EditText) findViewById(R.id.et_news_id);
        button= (Button) findViewById(R.id.btn_news_detail);
        btn_wechat= (Button) findViewById(R.id.btn_wechat);
        tv_wechat= (TextView) findViewById(R.id.tv_wechat);
        btn_wechat.setOnClickListener(this);
        button.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        Intent intent;
        switch (view.getId()){
            case R.id.btn_news_detail:
//                newsId=editText.getText().toString().trim();
//                intent=new Intent(this,NewsDetailActivity.class);
//                intent.putExtra("newsId",newsId);
//                startActivity(intent);
                intent = new Intent(this, TestActivity.class);
                startActivity(intent);
                break;
            case R.id.btn_wechat:
                HttpRequest request=new HttpRequest(Api.WECHAT_BASE_URL);
                request.getWeChatData("1", new RequestListener<WeChat>() {
                    @Override
                    public void success(WeChat data) {
                        tv_wechat.setText(data.getReason());
                    }

                    @Override
                    public void failed(String error) {
                        tv_wechat.setText(error);
                    }
                });
                break;
        }
    }
}
